#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

typedef struct Usr
{
	int iId;
	char caName[32];
	float fScore;
}Usr;

int main(int argc, char *argv[])
{	
	if (2 != argc)
	{
		exit(EXIT_FAILURE);
	}
	FILE *file = fopen(argv[1], "r");
	
	long pos = ftell(file);
	printf("pos = %ld\n", pos);

	Usr usr;
	int ret = 0;
	while (1)
	{
		ret = fscanf(file, "%d%s%f", &usr.iId
					     , usr.caName, &usr.fScore);
		//读写位置会随着读写操作一起往后偏移
		//获得当前的读写位置
		pos = ftell(file);
		printf("pos = %ld\n", pos);
		//将读写位置设置在文件首部
//		rewind(file);

		if (0 >= ret)
		{
			fclose(file);
			break;
		}
		printf("id=%d,name=%s,score=%.1f\n"
			   , usr.iId, usr.caName, usr.fScore);
	}

	return 0;
}
